﻿using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.Client.Manager
{
    /// <summary>
    /// 服务管理
    /// </summary>
    abstract class ServiceManager
    {
        private static JsonSerializerSettings CamelCase_Setting = new JsonSerializerSettings()
        {
            ContractResolver = new CamelCasePropertyNamesContractResolver(),
            DateFormatHandling = DateFormatHandling.IsoDateFormat,
            DateFormatString = "yyyy-MM-dd HH:mm:ss"
        };

        private static JsonSerializerSettings Default_Setting = new JsonSerializerSettings()
        {
            ContractResolver = new DefaultContractResolver(),
            DateFormatHandling = DateFormatHandling.IsoDateFormat,
            DateFormatString = "yyyy-MM-dd HH:mm:ss"
        };

        private readonly IServiceClient client;

        protected ServiceManager(IServiceClient client)
        {
            this.client = client;
        }

        /// <summary>
        /// 获取客户端
        /// </summary>
        public IServiceClient Client
        {
            get
            {
                return this.client;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public JsonSerializerSettings JsonSerializerSettings
        {
            get
            {
                if (this.client.CamelCase)
                {
                    return CamelCase_Setting;
                }
                return Default_Setting;
            }
        }
    }
}
